import {BASEURL} from '../config/index'

export function $get(url){
  return $request(url,'GET')
}

export function $post(url){
  return $request(url,'POST')
 }

function $request(url,method) {
  wx.showLoading({
    title: '加载中...',
  })
  return new Promise((resolve,reject)=>{
    wx.request({
      method:method,
      url: BASEURL + url,
      success: (res) => {
        resolve(res.data)
      },
      fail:(error)=>{
        reject(error)
      },
      complete: () => {
        wx.hideLoading()
      },
    })
  })
}